<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019-10-15
 * Time: 15:40
 */

namespace app\admin\controller;

use app\common\controller\AdminController;
use app\admin\validate\Admin as AdminValidate;
use app\admin\model\Admin as adminModel;
use think\facade\View;
use think\facade\Request;
use think\facade\Db;
use think\facade\Session;
use think\exception\ValidateException;
use app\common\model\User as UserModel;

class Admin extends AdminController
{
	//管理员
	public function adminList()
	{
		if(Request::isAjax()){
			//管理员
			$admins = Db::name('admin')->select();
			
			$count = $admins->count();
			if($admins){
				$res = ['code'=>0,'msg'=>'','count'=>$count];
				foreach($admins as $k => $v){
					$data = ['id'=>$v['id'],'loginname'=>$v['username'],'telphone'=>$v['mobile'],'email'=>$v['email'],'role'=>$v['auth_group_id'],'ip'=>$v['last_login_ip'],'check'=>$v['status'],'logintime'=>date("Y-m-d",$v['last_login_time'])];
					$res['data'][] = $data;
				}
			}
			return json($res);
			}
		return View::fetch('list');
	}

	
	//管理员审核
	public function adminCheck()
	{
		$data = Request::param();

		//获取状态
		$res = Db::name('admin')->where('id',$data['id'])->save(['status' => $data['status']]);
		if($res){
			if($data['status'] == 1){
				return json(['code'=>0,'msg'=>'设置管理员通过','icon'=>6]);
			} else {
				return json(['code'=>0,'msg'=>'管理员已取消','icon'=>5]);
			}
			
		}else {
			return json(['code'=>1,'msg'=>'审核出错']);
		}
	
	}
	
	//管理员编辑
	public function adminForm()
	{
		//
		return View::fetch('adminform');
	}
	
	public function info()
    {
        //
		return View::fetch('set/user/info');
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function repass()
    {
        //
		return View::fetch('set/user/repass');
    }
}